import pandas as pd
import numpy as np
from datetime import datetime, timedelta

# 参数
start_time = datetime(2025, 7, 14, 0, 0)
points = 60 * 24 * 7        # 7 天，1 分钟粒度
np.random.seed(42)

# 时间戳
timestamps = [start_time + timedelta(minutes=i) for i in range(points)]

# 模拟 5 个指标：CPU、内存、磁盘 IO、网络入/出
def sine_noise(base, amp, phase, noise_scale=0.05):
    return base + amp * np.sin(np.linspace(0, phase * 2 * np.pi, points)) + np.random.normal(0, noise_scale, points)

data = {
    "metric_name": ["usage_active"] * points,
    "value": sine_noise(50, 30, 3, 2).clip(0, 100),
    "timestamp_value": timestamps,
    # 额外 4 列（便于 TimeSeriesData 多变量）
    "mem_used": sine_noise(60, 20, 2, 1.5).clip(0, 100),
    "disk_io": sine_noise(40, 25, 4, 3).clip(0, 100),
    "network_in": sine_noise(30, 15, 1, 2).clip(0, 100),
    "network_out": sine_noise(25, 12, 1.5, 1.8).clip(0, 100)
}

# 生成长表格式：metric_name, value, timestamp_value
rows = []
for i in range(points):
    for metric, col in [
        ("usage_active", "value"),
        ("mem_used", "mem_used"),
        ("disk_io", "disk_io"),
        ("network_in", "network_in"),
        ("network_out", "network_out")
    ]:
        rows.append({
            "metric_name": metric,
            "value": data[col][i],
            "timestamp_value": timestamps[i]
        })

df = pd.DataFrame(rows)
df.to_csv("all_test.csv", index=False, date_format="%Y/%m/%d %H:%M")
print("✅ 已生成 5 列模拟数据：all_test.csv")